package com.example.springboot.controller;

import com.example.springboot.common.Result;
import com.example.springboot.controller.request.AppointmentPageRequest;
import com.example.springboot.controller.request.AppointmentPageRequest;
import com.example.springboot.entity.Appointment;
import com.example.springboot.entity.Appointment;
import com.example.springboot.service.IAppointmentService;
import com.example.springboot.service.IAppointmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin  //解决跨域错误
@RestController
@RequestMapping("/appointment")
//是rest风格的appointmentcontroller
public class AppointmentController {

    @Autowired
    IAppointmentService appointmentService;


    //    appointmentPageRequest传入用户名和电话信息
    @GetMapping("/page")
    public Result page(AppointmentPageRequest appointmentPageRequest){
        //        返回数据 Result.success传入一个对象
        return Result.success(appointmentService.page(appointmentPageRequest));

    }

//    post put get delete对应增改查删四类操作
    //    新增会员
    @PostMapping("/save")
    public Result save(@RequestBody Appointment appointment){
        appointmentService.save(appointment);
        return Result.success();
    }

//    更新会员信息
    @PutMapping("/update")
    public Result update(@RequestBody Appointment appointment){
        appointmentService.update(appointment);
        return Result.success();
    }

    //    获取用户列表
    @GetMapping("/list")
    public Result list(){
        //        返回数据
        List<Appointment> appointments=appointmentService.list();
//        System.out.println("appointments内容是"+appointments);
        return Result.success(appointments);

    }


//    根据ID更新用户信息
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        Appointment appointment =appointmentService.getById(id);
        return Result.success(appointment);

    }

    //删除操作:
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        appointmentService.deleteById(id);
        return Result.success();
    }

}
